const express = require("express");
const mongoose = require("mongoose");
const bodyParser = require("body-parser");
const passport = require("passport");
// 实例化一个app
const app = express();
// body-parser node获取数据的中间件
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());


// 引入config
const db = require("./config/key").mongoURI;
// 使用mongoose链接数据库
mongoose.connect(db)
        .then(()=>{
            console.log("数据库链接成功了");
        })
        .catch(err =>{
            console.log(err);
        })
// 初始化passport
app.use(passport.initialize());       
require("./config/passport")(passport);

// 引入模型
const users = require("./router/api/user");
const profile = require("./router/api/profile");
// 使用user.js
app.use("/api/user",users);
app.use("/api/profile",profile);
// 监听端口号
const port = process.env.PORT || 5000;
app.listen(port,()=>{
    console.log(`server running on port ${port}`);
})